<template>
  <div class="wh-100 card cbox" style="background-color: white">
    <div class="d-flex-between-center  pl-24 ch50">
      <div class="fs-14 fw-6">随机抽查</div>
    </div>
    <div class="h-7   d-flex-align-center pl-24">
      <Select v-if="userInfo.resource == 1" class="w-10 ml-8" v-model="searchForm.schoolCode" clearable filterable @on-change="selectSchool"
              placeholder="所有高校">
        <Option v-for="item in schoolList" :value="item.schoolCode" :key="item.schoolCode">{{ item.schoolName }}</Option>
      </Select>
      <Select v-if="userInfo.resource == 1 || userInfo.resource == 2" class="w-15 ml-8" v-model="searchForm.college" @on-change="selectCollege"
              filterable clearable placeholder="所有院系">
        <Option v-for="item in collegeList" :value="item" :key="item">{{ item }}</Option>
      </Select>
      <Select v-if="userInfo.resource == 1 || userInfo.resource == 2 || userInfo.resource == 3" class="w-15 ml-8" v-model="searchForm.major"
              filterable clearable placeholder="专业">
        <Option v-for="item in zyList" :value="item" :key="item">{{ item }}</Option>
      </Select>
      <Button type="primary" @click="getRecordPage">查询</Button>
      <!--<div class="ml-auto mr-12">-->
      <!--  <Button type="primary" @click="exportAllData">导出全部数据</Button>-->
      <!--</div>-->
    </div>
    <div class="w-100 h-80 mt-8 " v-ref-height="refHeight">
      <Table
          id="table1"

          border
          :columns="tableColumns"
          :data="tableData"
          ref="table1"
          :height="refHeight.value"
      >
        <template slot="action" slot-scope="{ row, index }">
          <Button  type="primary" @click="startChecking(row)">
            开始核查
          </Button>

        </template>
      </Table>
      <div class="w-100 h-5  d-flex-align-center mt-16 ">
        <Page
            :total="total"
            :page-size="pages.pageSize"
            :current="pages.pageNo"
            @on-change="changePage"
            @on-page-size-change="changePageSize"
            show-elevator
            show-sizer
            show-total

            class-name="d-flex-center"
            size="small"
        />
      </div>
    </div>
  </div>
</template>

<script>
import TableV2 from '@/views/xboot-components/table/table-v2.vue';

import {  getCollegesApi, getSchoolsApi,getZysApi, getSpotcheckApi } from '../../api/bys/gxjyl/jyqx';
import { saveAs } from 'file-saver';
import XLSX from 'xlsx';
import cloneDeep from 'lodash/cloneDeep';
import { employerTelephoneVerification,studentPhoneCheck, materialVerification } from '@/views/dataVerification/enums';
import { getDictDataByType } from '@/api';

export default {
  components: { TableV2 },

  data() {
    return {
      refHeight: { value: 0 },
      employerTelephoneVerification,
      studentPhoneCheck,
      materialVerification,
      tableColumns: [],
      tableColumns_1: [
        {
          title: '高校名称',
          key: 'schoolName',
          minWidth: 200,
          align: 'center',
        },
        {
          title: '院系名称',
          key: 'college',
          minWidth: 200,
          align: 'center',
        },
        {
          title: '专业',
          key: 'profession',
          minWidth: 200,
          align: 'center',
          
        },
        {
          title: '姓名',
          key: 'studentName',
          minWidth: 200,
          align: 'center',
          
        },
        {
          title: '姓名',
          key: 'enterpriseName',
          minWidth: 200,
          align: 'center',
          
        },
        {
          title: '联系方式',
          key: 'studentMobile',
          minWidth: 200,
          align: 'center',
          
        },
        {
          title: '毕业去向',
          key: 'graduationCode',
          minWidth: 200,
          align: 'center',
          render: (h, params) => {
            let item = this.qxList.find(item => item.value === params.row.oneType);
            return h('div', item ? item.title : '');
          }
        },
        {
          title: '单位联系人',
          key: 'enterpriseContact',
          minWidth: 200,
          align: 'center',
          
        },
        {
          title: '单位联系方式',
          key: 'enterpriseMobile',
          minWidth: 200,
          align: 'center',
          
        },
        {
          title: '材料核查（学校）',
          key: 'materialAuditSchool',
          minWidth: 200,
          align: 'center',
          render: (h, params) => {
            let item = this.materialVerification.find(item => item.value == params.row.materialAuditSchool);
            return h('div', item ? item.title : '');
          }
        },
        {
          title: '材料核查说明（学校）',
          key: 'materialAuditMessageSchool',
          minWidth: 200,
          align: 'center',
          
        },
        {
          title: '材料核查（省级）',
          key: 'materialAudit',
          minWidth: 200,
          align: 'center',
          render: (h, params) => {
            let item = this.materialVerification.find(item => item.value == params.row.materialAudit);
            return h('div', item ? item.title : '');
          }
        },
        {
          title: '材料核查说明（省级）',
          key: 'materialAuditMessage',
          minWidth: 200,
          align: 'center',
          
        },
        {
          title: '学生电话核查（学校）',
          key: 'studentAuditSchool',
          minWidth: 200,
          align: 'center',
          render: (h, params) => {
            let item = this.studentPhoneCheck.find(item => item.value == params.row.studentAuditSchool);
            return h('div', item ? item.title : '');
          }
        },
        {
          title: '学生电话核查说明（学校）',
          key: 'studentAuditMessageSchool',
          minWidth: 200,
          align: 'center',
        },
        {
          title: '学生电话核查（省级）',
          key: 'studentAudit',
          minWidth: 200,
          align: 'center',
          render: (h, params) => {
            let item = this.studentPhoneCheck.find(item => item.value == params.row.studentAudit);
            return h('div', item ? item.title : '');
          }
        },
        {
          title: '学生电话核查说明（省级）',
          key: 'studentAuditMessage',
          minWidth: 200,
          align: 'center',
          
        },
        {
          title: '用人单位电话核查（学校）',
          key: 'enterpriseAuditSchool',
          minWidth: 200,
          align: 'center',
          render: (h, params) => {
            let item = this.employerTelephoneVerification.find(item => item.value == params.row.enterpriseAuditSchool);
            return h('div', item ? item.title : '');
          }
        },
        {
          title: '用人单位电话核查说明（学校）',
          key: 'enterpriseAuditMessageSchool',
          minWidth: 200,
          align: 'center',
        },
        {
          title: '用人单位电话核查（省级）',
          key: 'enterpriseAudit',
          minWidth: 200,
          align: 'center',
          render: (h, params) => {
            let item = this.employerTelephoneVerification.find(item => item.value == params.row.enterpriseAudit);
            return h('div', item ? item.title : '');
          }
        },
        {
          title: '用人单位电话核查说明（省级）',
          key: 'enterpriseAuditMessage',
          minWidth: 200,
          align: 'center',
          
        },
        {
          title: '其他核查情况（学校）',
          key: 'otherAuditSchool',
          minWidth: 200,
          align: 'center',
          
        },
        {
          title: '其他核查情况（省级）',
          key: 'otherAudit ',
          minWidth: 200,
          align: 'center',
          
        },
        {
          title: '核查时间（学校）',
          key: 'auditTimeSchool',
          minWidth: 200,
          align: 'center',
          
        },
        {
          title: '核查时间（省级）',
          key: 'auditTime',
          minWidth: 200,
          align: 'center',
          
        },
        {
          title: '学校是否核查',
          key: 'schoolAudit',
          align: 'center',
          width: 120,
          fixed: 'right',
          render: (h, params) => {
            return h('div', params.row.schoolAudit == 1 ? '已核查' : '未核查');
          }
        },
        {
          title: '省级是否核查',
          key: 'provinceAudit',
          align: 'center',
          width: 120,
          fixed: 'right',
          render: (h, params) => {
            return h('div', params.row.provinceAudit == 1 ? '已核查' : '未核查');
          }
        },
        {
          title: '操作',
          slot: 'action',
          align: 'center',
          width: 120,
          fixed: 'right'
        }
      ],
      tableData: [],
      schoolList: [],
      zyList: [],
      collegeList: [],
      searchForm: {
        schoolCode: '',
        schoolName: '',
        college: '',
        major: ''
      },
      qxList: [],
      userInfo: JSON.parse(Cookies.get('userInfo')),
      total:0,
      pages:{
        "pageNo": 1,
        "pageSize": 10,
      }
    };
  },
  methods: {
    selectSchool(val) {
      this.getCollegeList();
      this.getZyList();
    },
    getQxDict() {
      getDictDataByType('qx').then(res => {
        if (res.success) {
          this.qxList = res.result;
        }
      });
    },
    // 开始核查
    startChecking(row) {
      this.$router.push({ name: 'CheckDetails', query: { type: '1', idCard: row.idCard } });
    },
    selectCollege(val) {
      this.getZyList();
    },
    getRecordPage() {
      this.pages.pageNo=1
      this.getRecords()
    },
    getRecords(){
      let params ={
        "college": this.searchForm.college,
        "major": this.searchForm.major,
        "pageNo": this.pages.pageNo,
        "pageSize":this.pages.pageSize,
        "schoolCode": this.searchForm.schoolCode,
      }
      getSpotcheckApi(params).then(res => {
        this.tableData = res.result.records;
        this.total =res.result.total;
      });
    },

    getSchoolList() {
      // 学校
      getSchoolsApi().then(res => {
        if (res.success) {
          this.schoolList = res.result;
        }
      });
    },
    getCollegeList() {
      getCollegesApi({
        schoolCode: this.searchForm.schoolCode,
      }).then(res => {
        if (res.success) {
          this.collegeList = res.result;
        }
      })
    },
    getZyList() {
      getZysApi({
        schoolCode: this.searchForm.schoolCode,
        college: this.searchForm.college,
      }).then(res => {
        if (res.success) {
          this.zyList = res.result;
        }
      })
    },
    onRestWindow() {
      let t1 = cloneDeep(this.tableColumns_1);
      this.restTreeTableCellWidth(t1);
      this.tableColumns = t1;
    },
    changePage(e){
      this.pages.pageNo = e;
      this.getRecords()
    },
    changePageSize(e){
      this.pages.pageSize = e
      this.pages.pageNo = 1
      console.log(e);
      this.getRecordPage()
      // this.onRestWindow();
    }
  },
  mounted() {
    this.getQxDict()
    this.onRestWindow();
    window.addEventListener('resize', this.onRestWindow);
    let userInfo = JSON.parse(Cookies.get('userInfo'));
    // if (userInfo.resource == 1) {
    //   let arr1 = [
    //
    //   ];
    //   let arr01 = this.restTableCellWidth(arr1);
    //   this.tableColumns = arr01.concat(this.tableColumns);
    //
    // }
    // if (userInfo.resource == 2) {
    //   let arr1 = [
    //     {
    //       title: '院系名称',
    //       key: 'college',
    //       minWidth: 200,
    //       align: 'center',
    //       
    //     }
    //   ];
    //   let arr01 = this.restTableCellWidth(arr1);
    //   this.tableColumns = arr01.concat(this.tableColumns);
    // }
    this.getCollegeList();
    this.getSchoolList();
    this.getZyList();
    this.getRecordPage();
  },
  beforeDestroy() {
    window.removeEventListener('resize', this.onRestWindow);
  }

};
</script>
<style scoped lang="less">
.cbox {
  padding: 0 10px;
  box-sizing: border-box;
}

.h-7 {
  height: 7%;
}


.ch50 {
  height: 50px;
}

.ctable {
  // /deep/.ivu-table-body {
  //     height: 74%;
  // }
  @media (max-width: 1920px) {
    /deep/ .ivu-table-body {
      height: 78% !important;
    }
  }

  @media (min-width: 1921px) and (max-width: 3440px) {
    /deep/ .ivu-table-body {
      height: 74.5% !important;
    }
  }
}

</style>